/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.config.controller;

import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.punish.config.model.ConfigRegisterCaseFile;
import com.icinfo.cloud.provider.punish.config.service.IConfigRegisterCaseFileService;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import com.icinfo.framework.tools.utils.StringUtils;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.*;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;

/**
 * 描述: 立案材料配置表 config_register_case_file 对应的Controller类.<br>
 *
 * @author framework generator
 * @date 2022年11月30日
 */
@RestController
@RequestMapping("/punish/ucase/registerCaseConfigFile")
public class ConfigRegisterCaseFileController extends BaseController {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(ConfigRegisterCaseFileController.class);

    @Autowired
    private IConfigRegisterCaseFileService configRegisterCaseFileService;


    /**
     * 立案材料配置列表-配置参数-获取材料列表
     * @param relId
     * @return
     */
    @GetMapping("/getFileListByRelId")
    public Result<List<ConfigRegisterCaseFile>> getFileListByRelId(String relId){
        return Result.success(configRegisterCaseFileService.getFileListByRelId(relId));
    }

    /**
     * 删除立案配置材料
     * @param id
     * @return
     */
    @GetMapping("/delete")
    public Result<String> delete(String id){
        if (StringUtils.isBlank(id)){
            return Result.error("材料id不能为空");
        }
        configRegisterCaseFileService.delete(id);
        return Result.success("删除成功");
    }

    /**
     * 根据处罚事项获取材料列表
     * @param paramNumber 编码规则：机构code+处罚code
     * @return
     */
    @GetMapping("/getFileListByParamNumber")
    public Result<List<ConfigRegisterCaseFile>> getFileListByParamNumber(String paramNumber){
        List<String> list = Arrays.asList(paramNumber.split(Constant.STRING_COMMA));
        if (CollectionUtils.isEmpty(list) && list.size() == 0){
            return Result.error("paramNumber不能为空");
        }
        return Result.success(configRegisterCaseFileService.getFileListByParamNumber(list));
    }
}
